package com.lagou.demo.controller;

import com.lagou.demo.service.IDemoService;
import com.lagou.edu.mvcframework.annotations.LagouAutowired;
import com.lagou.edu.mvcframework.annotations.LagouController;
import com.lagou.edu.mvcframework.annotations.LagouRequestMapping;
import com.lagou.edu.mvcframework.annotations.LagouSecurity;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@LagouSecurity({"lagou","admin"})
@LagouController
@LagouRequestMapping("/user")
public class UserController {


    @LagouAutowired
    private IDemoService demoService;


    /**
     * URL: /demo/query?name=lisi
     * @param request
     * @param response
     * @param username
     * @return
     */
    @LagouRequestMapping("/delete")
    public String query(HttpServletRequest request, HttpServletResponse response, String username) {
        try {
            response.setCharacterEncoding("GBK");
            response.getWriter().println("删除成功");
        }catch (Exception e){
            e.printStackTrace();
        }
        return demoService.get(username);
    }

    /**
     *
     * @param request
     * @param response
     * @param username
     * @return
     */
    @LagouRequestMapping("/login")
    public String login(HttpServletRequest request, HttpServletResponse response,String username,String password) {
        try {
            response.setCharacterEncoding("GBK");
            response.getWriter().println("登录成功");
        }catch (Exception e){
            e.printStackTrace();
        }
        return demoService.login(username, password);
    }
}
